/*  
 *  ------ [802_10] - set low power state in XBee module  -------- 
 *  
 *  Explanation: This program shows how to set different low power states 
 *  in XBee-802.15.4 modules
 *   Pin Hibernate (SM = 1):  XBee is put to sleep and is wake up by setting 
 *                            a pin high and low
 *   Pin Hibernate (SM = 2):  The same as before, but more consumption and faster
 *                            wake up 
 *
 *  Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details. 
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 *  
 *  Version:           0.1 
 *  Design:            David Gascón 
 *  Implementation:    Yuri Carmona
 */

#include <WaspXBee802.h>


void setup()
{  
  // init USB port
  USB.ON();
  USB.println(F("802_10 example"));

  // init XBee 
  xbee802.ON();  
     
  // set sleep mode
  xbee802.setSleepMode(1); 
  
}


void loop()
{
  ////////////////////////////////////
  // 1. Set sleep mode
  ////////////////////////////////////
  
  // set red LED during sleep time 
  Utils.setLED(LED0, LED_ON);
  
  // put XBee to sleep
  xbee802.sleep();
  
  // wait 10 seconds in sleep mode
  delay(10000);  
    
  
  ////////////////////////////////////
  // 2. Wake up the XBee module
  ////////////////////////////////////
  
  // wake XBee up
  xbee802.wake();
  
  // switch LED off when leaving sleep mode
  Utils.setLED(LED0, LED_OFF);
 
  
  delay(5000);
}


